// pages/order/list/index.js
import { reqGetOrderList } from '../../../api/oderPay'
//获取订单列表

Page({
  // 页面的初始数据
  data: {
    orderList: [],
    page: 1, //页数
    limit: 10, //每次多少条
    total: 0,
    isLoading: false
  },
  //获取订单详情
  async reqOrderList() {
    this.data.isLoading = true
    const { page, limit } = this.data
    const res = await reqGetOrderList(page, limit)
    console.log(res)
    if (res.code === 200) {
      this.data.isLoading = false
      this.setData({
        orderList: [...this.data.orderList, ...res.data.records],
        total: res.data.total
      })
    }
  },

  //下拉刷新
  onReachBottom(e) {
    if (this.data.isLoading) return
    if (this.data.orderList.length === this.data.total) return
    this.setData({
      page: this.data.page + 1
    })
    this.reqOrderList()
  },
  onLoad() {
    // console.log(...this.data)
    this.reqOrderList()
  }
})
